package clas.ac.cn.common.vo;

import clas.ac.cn.common.exception.IException;
import clas.ac.cn.common.exception.NotFoundException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * @author z
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class CommonResponse<T> implements Serializable {
    private Integer code;
    private String message;

    private T data;
    public CommonResponse(Integer code, String message){
        this.code=code;
        this.message=message;
    }

    public CommonResponse(IException e){
        this.code=e.getCode();
        this.message=e.getMessage();
        this.data=null;
    }
    public CommonResponse(NotFoundException e){
        this.code=e.getCode();
        this.message=e.getMessage();
        this.data=null;
    }
    public CommonResponse(T t){
        this.code=1;
        this.message="";
        this.data=t;
    }

    public CommonResponse(int code,String message,T t){
        this.code=1;
        this.message="";
        this.data=t;
    }


}
